<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="app">

    </div>
</body>
<script>
    const xhr = new XMLHttpRequest();
	xhr.responseType = "json";
	xhr.open("get","/userList");// http://zhangpeiyue.com/userList
    xhr.send();
	xhr.onload = function(){
		document.querySelector("#app").innerHTML = xhr.response.userList.map(item=>(`
		    <button onclick="sendVote(${item.id},this)">${item.username}-${item.voteNum}</button>
		`)).join("")
    }

	function sendVote(id,_this){
		console.log(_this)
		const xhr = new XMLHttpRequest();
		xhr.responseType = "json";
		xhr.open("get","/vote/"+id);
		xhr.send();
		xhr.onload = function(){
			const {ok,msg,info} = xhr.response;
			if(ok === 1){
                _this.innerText = info.username+"-"+info.voteNum;
            }else{
				alert(msg);
            }
        }
    }
</script>
</html>